package com.share.dgs.scalar;

import com.netflix.graphql.dgs.DgsScalar;
import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
import graphql.schema.CoercingParseValueException;
import graphql.schema.CoercingSerializeException;

import java.util.Objects;

/**
 * @author caifan
 * @created 2021/3/10
 * description:
 */
@DgsScalar(name = "Long")
public class LongCoercing implements Coercing<Long, Long> {
    @Override
    public Long serialize(Object dataFetcherResult) throws CoercingSerializeException {
        if (dataFetcherResult instanceof Long && Objects.nonNull(dataFetcherResult)) {
            return (Long)dataFetcherResult;
        }
        return null;
    }

    @Override
    public Long parseValue(Object input) throws CoercingParseValueException {
        if (input instanceof Long && Objects.nonNull(input)) {
            return (Long)input;
        }
        return null;
    }

    @Override
    public Long parseLiteral(Object input) throws CoercingParseLiteralException {
        if (input instanceof Long && Objects.nonNull(input)) {
            return (Long)input;
        }
        return null;
    }
}
